package com.zhss.netty.discard;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

import java.nio.ByteBuffer;

/**
 * @ClassName NettyDiscardHandler
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/9/7 16:23
 * @Version 1.0
 */
public class NettyDiscardHandler extends ChannelInboundHandlerAdapter {
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		ByteBuf buffer = (ByteBuf) msg;
		try {

			System.out.println("收到消息");
			while (buffer.isReadable()) {
				System.out.println((char) buffer.readByte());
			}
		}finally {
			ReferenceCountUtil.release(msg);
		}
	}
}
